/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef NODE_CRYPTO_SHA1_H_
#define NODE_CRYPTO_SHA1_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <string>
#include <cstdint>
#include <openssl/sha.h>
#include <openssl/crypto.h>

#include "node/macros.h"

namespace node {
    namespace crypto {

        class BigNumber;

        class Sha1Hash
        {
        public:
            Sha1Hash(void);
            ~Sha1Hash(void);

        public:
            void Initialize(void);
            void Finalize(void);

            void UpdateBigNumbers(BigNumber*, ...);
            void UpdateData(const ::std::uint8_t*, ::std::size_t);
            void UpdateData(const ::std::string&);

            const ::std::uint8_t* GetDigest(void) const { return &digest_[0]; }
            int GetLength(void) const { return SHA_DIGEST_LENGTH; }

        private:
            SHA_CTX         ctx_;
            ::std::uint8_t  digest_[SHA_DIGEST_LENGTH];

            DISALLOW_COPY_AND_ASSIGN(Sha1Hash);
        };

    }
}

#endif // NODE_CRYPTO_SHA1_H_
